﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4委托与事件
{
    //事件发布器
    class EventSample
    {
        public delegate void MyEnventDelegate(object obj, MyEventArgs args);

        public event MyEnventDelegate MyEvent;

        public void My(MyEventArgs args)
        {
            MessageBox.Show("喵，我是");
            if (MyEvent != null)
            {
                MessageBox.Show("喵，我是");
                MyEvent(this, args);
            }
        }

    }
    //事件响应者类
    class Sub
    {
        public void Run(object obj, MyEventArgs args)
        {

        }
    }

    class Main
    {
        public void MainThord()
        {
            EventSample e = new EventSample();
            Sub s1 = new Sub();
            Sub s2 = new Sub();
            e.MyEvent += s1.Run;
            e.MyEvent += s2.Run;
            e.My(new MyEventArgs());
        }
    }
    //委托携带的信息
    class MyEventArgs : EventArgs
    {
        public string Name;
        public int Age;
    }
}
